package com.snowRemovingUser.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.snowRemovingUser.domain.TInterfaces;
import com.snowRemovingUser.dto.WeatherDetail;
import com.snowRemovingUser.dto.WeatherDto;
import com.snowRemovingUser.dto.WeatherEvent;
import com.snowRemovingUser.service.ITInterfacesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 数据管理Controller
 *
 * @author liguang
 * @date 2023-08-21
 */
@RestController
@RequestMapping("/snowRemoving/interfaces")
public class TInterfacesController extends BaseController
{
    @Autowired
    private ITInterfacesService tInterfacesService;

    /**
     * 查询数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:interfaces:list')")
    @GetMapping("/list")
    public TableDataInfo list(TInterfaces tInterfaces)
    {
        startPage();
        List<TInterfaces> list = tInterfacesService.selectTInterfacesList(tInterfaces);
        return getDataTable(list);
    }

    /**
     * 导出数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:interfaces:export')")
    @Log(title = "数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TInterfaces tInterfaces)
    {
        List<TInterfaces> list = tInterfacesService.selectTInterfacesList(tInterfaces);
        ExcelUtil<TInterfaces> util = new ExcelUtil<TInterfaces>(TInterfaces.class);
        util.exportExcel(response, list, "数据管理数据");
    }

    /**
     * 获取数据管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:interfaces:query')")
    @GetMapping(value = "/{id}")
    public TableDataInfo getInfo(@PathVariable("id") Long id)
    {

        TInterfaces tInterfaces = new TInterfaces();
        tInterfaces.setParentId(id);
        startPage();
        List<TInterfaces> list = tInterfacesService.selectTInterfacesList(tInterfaces);
        return getDataTable(list);

    }

    /**
     * 新增数据管理
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:interfaces:add')")
    @Log(title = "数据管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TInterfaces tInterfaces)
    {
        return toAjax(tInterfacesService.insertTInterfaces(tInterfaces));
    }

    /**
     * 修改数据管理
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:interfaces:edit')")
    @Log(title = "数据管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TInterfaces tInterfaces)
    {
        return toAjax(tInterfacesService.updateTInterfaces(tInterfaces));
    }

    /**
     * 删除数据管理
     */
    @PreAuthorize("@ss.hasPermi('snowRemoving:interfaces:remove')")
    @Log(title = "数据管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tInterfacesService.deleteTInterfacesByIds(ids));
    }



    /**
     * 数据管理
     */
    @PostMapping("/weather")
    @Anonymous
    public void AddDetails(@RequestBody WeatherDto weatherDto) throws JsonProcessingException {

        if (weatherDto.getPushType()==0){

            tInterfacesService.AddWeatherDetails(weatherDto);

        }else {

            tInterfacesService.AddEventDetails(weatherDto);
        }
    }




    /**
     * 获取数据管理详细信息
     */
    @GetMapping(value = "/getExpand/{id}")
    public TableDataInfo getExpandDetail(@PathVariable("id") Long id) throws JsonProcessingException {


        startPage();
        List<WeatherDetail> list = tInterfacesService.selectExpandDetail(id);
        return getDataTable(list);

    }


    /**
     * 获取数据管理详细信息
     */
    @GetMapping(value = "/getEventExpand/{id}")
    public TableDataInfo getEventExpandDetail(@PathVariable("id") Long id){


        startPage();
        List<WeatherEvent> list = tInterfacesService.selectEventExpandDetail(id);
        return getDataTable(list);

    }












}
